package com.srt.controller;


import com.srt.model.VedioCutoff;
import com.srt.service.VedioCutoffService;
import com.srt.vo.VedioCutoffExportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author rd06
 * @since 2021-05-11
 */
@Controller
@RequestMapping("/vedioCutoff")
public class VedioCutoffController {
    @Autowired
    VedioCutoffService vedioCutoffService;

    /**
     * 渠道添加页面
     */
    @GetMapping("/to_save/{catalogId}")
    public String toSave(@PathVariable("catalogId") Long catalogId, HttpServletRequest request) {
        request.setAttribute("catalogId", catalogId);
        return "vedio_cutoff";
    }

    /**
     * 列表
     *
     * @param cataLogId
     * @return
     */
    @GetMapping("/{catalogId}")
    public String listByCataLogId(@PathVariable("catalogId") Long cataLogId,HttpServletRequest request) {
        request.setAttribute("cataLogId",cataLogId);
        request.setAttribute("vedioList",vedioCutoffService.queryListByCataLogId(cataLogId));
        return "vedio_list";
    }

    /**
     * 保存
     *
     * @param catalogId
     * @param vedioCutoffList
     * @return
     */
    @PostMapping("/save/{catalogId}")
    @ResponseBody
    public String save(@PathVariable("catalogId") Long catalogId, @RequestBody List<VedioCutoff> vedioCutoffList) {
        vedioCutoffService.save(vedioCutoffList, catalogId);
        return "OK";
    }

    /**
     * 导出
     */
    @PostMapping("/export/{catalogId}")
    public void export(VedioCutoffExportVO vedioCutoffExportVO, HttpServletResponse response) throws IOException {
        vedioCutoffService.export(vedioCutoffExportVO, response);
    }
}

